<?php $this->renderPartial('/admin/menu/reports');?>
<h4><?php echo Yii::t('helpdesk','Dashboard'); ?></h4>
<?php 
foreach(Yii::app()->user->getFlashes() as $key => $message){
	echo '<div class="'.$key.'"><p>'.$message."</p></div>\n";
}
?>
<div id="chart1"></div>
<br>
<table style="width: 100%;" class="table table-striped table-nonfluid">
<tbody>
	<tr>
        <th><?php echo Yii::t('helpdesk','Department'); ?></th>
        <th width="80px"><?php echo Yii::t('helpdesk','Open'); ?></th>
        <th width="80px"><?php echo Yii::t('helpdesk','Closed'); ?></th>
        <th width="80px"><?php echo Yii::t('helpdesk','Total'); ?></th>
        <th width="80px"><?php echo Yii::t('helpdesk','Rate'); ?></th>
	</tr>
    <?php if(!empty($arrDeptStatistic)): ?>
    <?php foreach($arrDeptStatistic as $R): ?>
	<tr>
    	<td><?php echo $R['category_name']; ?></td>
        <td><a target="_blank" href="/tickets/<?php echo Utils::uri_encode($R['category_name']).'.'.$R['category_id']; ?>.html/?status=1"><?php echo $R['open']; ?></a></td>
        <td><a target="_blank" href="/tickets/<?php echo Utils::uri_encode($R['category_name']).'.'.$R['category_id']; ?>.html/?status=0"><?php echo $R['closed']; ?></a></td>
        <td><a target="_blank" href="/tickets/<?php echo Utils::uri_encode($R['category_name']).'.'.$R['category_id']; ?>.html"><?php echo $R['total']; ?></a></td>
        <td><?php echo round(100*$R['closed']/$R['total'], 2); ?>%</td>
    </tr>
    <?php endforeach; ?>
    <?php else: ?>
    <tr>
    	<td colspan="2"><?php echo Yii::t('helpdesk','No data found'); ?></td>
    </tr>
    <?php endif; ?>   
</tbody></table>

<script src="js/highcharts/highcharts.js"></script>
<script type="text/javascript">
$(function () {
	//chart 1
	var chartDepts = new Array();
	chartDepts['categories'] = [
		<?php foreach($arrDeptStatistic as $i=>$R): ?>
			<?php echo '"' . addslashes($R['category_name']) . '"' ?>
			<?php if($i < count($arrDeptStatistic)-1): echo ','; endif; ?>
		<?php endforeach; ?>
	];
	chartDepts['data'] = [ { name: 'Open', data: [
		<?php foreach($arrDeptStatistic as $i=>$R): ?>
			<?php echo $R['open']; ?><?php if($i < count($arrDeptStatistic)-1): echo ','; endif; ?>
		<?php endforeach; ?>
		]},
		{ name: 'Closed', data: [
		<?php foreach($arrDeptStatistic as $i=>$R): ?>
			<?php echo $R['closed']; ?><?php if($i < count($arrDeptStatistic)-1): echo ','; endif; ?>
		<?php endforeach; ?>
		]},
	];
	$('#chart1').highcharts({
		chart: {
			type: 'column'
		},
		title: {
			text: '<?php echo Yii::t('helpdesk','Departments'); ?>'
		},
		xAxis: {
			categories: chartDepts['categories']
		},
		yAxis: {
			min: 0,
			title: {
				text: '<?php echo Yii::t('helpdesk','Number of tickets'); ?>'
			},
			stackLabels: {
				enabled: true,
				style: {
					fontWeight: 'bold',
					color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
				}
			}
		},
		legend: {
			align: 'right',
			x: -70,
			verticalAlign: 'top',
			y: 20,
			floating: true,
			backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
			borderColor: '#CCC',
			borderWidth: 1,
			shadow: false
		},
		tooltip: {
			formatter: function() {
				return '<b>'+ this.x +'</b><br/>'+
					this.series.name +': '+ this.y +'<br/>'+
					'Total: '+ this.point.stackTotal;
			}
		},
		plotOptions: {
			column: {
				stacking: 'normal',
				dataLabels: {
					enabled: true,
					color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
					style: {
						textShadow: '0 0 3px black, 0 0 3px black'
					}
				}
			}
		},
		series: chartDepts['data'],
		credits: {
			enabled: false	
		}
	});
});
</script>

<hr>
<?php foreach($arrSubjectStatistic as $key=>$R): ?>
<div id="chart_<?php echo addslashes($key); ?>"></div>
<table style="width: 100%;" class="table table-striped table-nonfluid">
<tbody>
	<tr>
        <th colspan="2"><?php echo Yii::t('helpdesk','Department'); ?> <?php echo addslashes($key); ?></th>
	</tr>
    <?php foreach($R as $P): ?>
	<tr>
    	<td><?php echo $P['subject_name']; ?></td>
        <td width="100px;"><?php echo $P['total']; ?></td>
    </tr>
    <?php endforeach; ?>  
</tbody></table>
<script type="text/javascript">
$(function () {
	//chart 2
	var chartSubjects = new Array();
	chartSubjects = [
		<?php foreach($R as $i=>$P): ?>
			<?php echo '["' . addslashes($P['subject_name']) . '", '.$P['total'].']' ?>
			<?php if($i < count($R)-1): echo ','; endif; ?>
		<?php endforeach; ?>
	];
	$('#chart_<?php echo addslashes($key); ?>').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: 1,//null,
            plotShadow: false
        },
        title: {
            text: '<?php echo Yii::t('helpdesk','Subjects'); ?> <?php echo addslashes($key); ?>'
        },
        tooltip: {
    	    pointFormat: '{series.name}: <b>{point.percentage:.2f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.2f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: chartSubjects
        }],
		credits: {
			enabled: false	
		}
    });
});
</script>
<?php endforeach; ?>

